var baseUrl = top.location.href.split('?')[0];
export var darkStyle = {
    styleUrl: 'bmapGL/dugis-demo-3d/mapstyle/testJson0513.json',
    style: {
        styleJson: [{
            "featureType": "land",
            "elementType": "geometry",
            "stylers": {
                "visibility": "on",
                "color": "#091220ff",
            },
        }],
    },
};
var snowStyle = {
    styleUrl: 'bmapGL/dugis-demo-3d/mapstyle/snowStyle.json',
    style: {
        styleJson: [{
            "featureType": "land",
            "elementType": "geometry",
            "stylers": {
                "visibility": "on",
                "color": "#fff",
            }
        }]
    },
};

export const purpleStyle = {
    styleUrl: 'bmapGL/dugis-demo-3d/mapstyle/test_map_config.json',
    style: {
        styleJson: [{
            "featureType": "land",
            "elementType": "geometry",
            "stylers": {
                "visibility": "on",
                "color": "#40495aff",
            }
        }]
    },
};

var whiteStyle = {
    styleUrl: 'bmapGL/dugis-demo-3d/mapstyle/whiteStyle.json',
    style: {
        styleJson: [{
            "featureType": "land",
            "elementType": "geometry",
            "stylers": {
                "visibility": "on",
                "color": "#edf3f3ff",
            }
        }]
    },
};

export function initMap(options) {
    options = Object.assign({
        tilt: 60,
        heading: 0
    }, options);
    var map = new BMapGL.Map('map_container', {
        restrictCenter: false,
    });
    map.enableKeyboard();
    map.enableScrollWheelZoom();
    map.enableInertialDragging();
    map.enableContinuousZoom();

    map.setDisplayOptions(options.displayOptions || {
        indoor: false,
        poi: true,
        skyColors: options.skyColors || [
            'rgba(5, 5, 30, 0.01)',
            'rgba(5, 5, 30, 1.0)'
        ]
    });
    if (options.center && options.zoom) {
        let center = options.center;
        if (center instanceof Array) {
            center = new BMapGL.Point(options.center[0], options.center[1])
        }
        map.centerAndZoom(center, options.zoom);
    }

    map.setTilt(options.tilt);
    map.setHeading(options.heading);
    if (options.style) {
        map.setOptions(options.style);
    }
    return map;
}